//
//  AppDelegate.m
//  guess
//
//  Created by fank on 15/11/3.
//  Copyright © 2015年 fank. All rights reserved.
//

#define WPBannerID @"1662acb505a9055e23ee5bd86390bc10"


#import "AppDelegate.h"
#import "GHttpEnqine.h"
#import "GJokeVC.h"
#import "GGuessVC.h"
#import "QiuBaiVC.h"
#import "Define.h"
#import "UMSocialSnsService.h"
//#import "CustomOfferViewController.h"

@interface AppDelegate ()



@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    
    self.window =[[UIWindow alloc]init];
//    [self registWPBanner];
    [self setTabBar];
    return YES;
}



- (void) setTabBar{
    UITabBarController *tabViewController = [[UITabBarController alloc]init];
    self.window.rootViewController =tabViewController;
    [tabViewController setSelectedIndex:2];
    
    
    
    
//    int xLocate =(kscreenWith -320)/2;
//    [AppConnect displayAd:tabViewController adSize:@"dads" showX:xLocate showY:(int)kscreenHeight -99];
    
    GJokeVC *jokeCV =[[GJokeVC alloc]initWithNibName:@"GJokeVC" bundle:[NSBundle mainBundle]];
    QiuBaiVC *qiuBaiVC = [[QiuBaiVC alloc]initWithNibName:@"QiuBaiVC" bundle:[NSBundle mainBundle]];
    GGuessVC *guessVC =[[GGuessVC alloc]initWithNibName:@"GGuessVC" bundle:[NSBundle mainBundle]];
//    CustomOfferViewController  *cv = [CustomOfferViewController new];
    
    
    NSMutableArray *controllers=[[NSMutableArray alloc] initWithCapacity:2];
    [controllers addObject:jokeCV];
    [controllers addObject:qiuBaiVC];
    [controllers addObject:guessVC];
//    [controllers addObject:cv];
    
    tabViewController.viewControllers =controllers;
    
    
    UITabBar *tabBar = tabViewController.tabBar;
    [tabBar setTintColor: [UIColor blackColor]];
    
    // First
    UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
    UIImage* tabBarItem1Image = [UIImage imageNamed:@"haha"];
    UIImage *scaledTabBarItem1Image = [UIImage imageWithCGImage:[tabBarItem1Image CGImage] scale:(tabBarItem1Image.scale * 2.0) orientation:(tabBarItem1Image.imageOrientation)];
    UIImage* tabBarItem1SelectedImage = [UIImage imageNamed:@"haha"];
    UIImage *scaledTabBarItem1SelectedImage = [UIImage imageWithCGImage:[tabBarItem1SelectedImage CGImage] scale:(tabBarItem1SelectedImage.scale * 1.6) orientation:(tabBarItem1SelectedImage.imageOrientation)];
    (void)[tabBarItem1 initWithTitle:@"笑话" image:scaledTabBarItem1Image selectedImage:scaledTabBarItem1SelectedImage];
    
    // Second
    UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
    UIImage* tabBarItem2Image = [UIImage imageNamed:@"video"];
    UIImage *scaledTabBarItem2Image = [UIImage imageWithCGImage:[tabBarItem2Image CGImage] scale:(tabBarItem2Image.scale * 2.0) orientation:(tabBarItem2Image.imageOrientation)];
    UIImage* tabBarItem2SelectedImage = [UIImage imageNamed:@"video"];
    UIImage *scaledTabBarItem2SelectedImage = [UIImage imageWithCGImage:[tabBarItem2SelectedImage CGImage] scale:(tabBarItem2SelectedImage.scale * 1.6) orientation:(tabBarItem2SelectedImage.imageOrientation)];
    (void)[tabBarItem2 initWithTitle:@"视频" image:scaledTabBarItem2Image selectedImage:scaledTabBarItem2SelectedImage];
    
    // Third
    UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
    UIImage* tabBarItem3Image = [UIImage imageNamed:@"think"];
    UIImage *scaledTabBarItem3Image = [UIImage imageWithCGImage:[tabBarItem3Image CGImage] scale:(tabBarItem3Image.scale * 2.0) orientation:(tabBarItem3Image.imageOrientation)];
    UIImage* tabBarItem3SelectedImage = [UIImage imageNamed:@"think"];
    UIImage *scaledTabBarItem3SelectedImage = [UIImage imageWithCGImage:[tabBarItem3SelectedImage CGImage] scale:(tabBarItem3SelectedImage.scale * 1.6) orientation:(tabBarItem3SelectedImage.imageOrientation)];
    (void)[tabBarItem3 initWithTitle:@"猜一猜" image:scaledTabBarItem3Image selectedImage:scaledTabBarItem3SelectedImage];
    
    
//    UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];
//    UIImage* tabBarItem4Image = [UIImage imageNamed:@"adv"];
//    UIImage *scaledTabBarItem4Image = [UIImage imageWithCGImage:[tabBarItem4Image CGImage] scale:(tabBarItem4Image.scale * 2.0) orientation:(tabBarItem4Image.imageOrientation)];
//    UIImage* tabBarItem4SelectedImage = [UIImage imageNamed:@"adv"];
//    UIImage *scaledTabBarItem4SelectedImage = [UIImage imageWithCGImage:[tabBarItem4SelectedImage CGImage] scale:(tabBarItem4SelectedImage.scale * 1.6) orientation:(tabBarItem4SelectedImage.imageOrientation)];
//    (void)[tabBarItem4 initWithTitle:@"推荐软件" image:scaledTabBarItem4Image selectedImage:scaledTabBarItem4SelectedImage];
    
    [self share];

    [self.window makeKeyAndVisible];
    
    // And Others Tabs － 同样的方法
    
}

#pragma mark-
#pragma mark-社会分享
-(void)share
{
    //设置友盟社会化组件appkey
    [UMSocialData setAppKey:UmengAppkey];
    
    //打开调试log的开关
    [UMSocialData openLog:YES];
    
    //设置微信AppId，设置分享url，默认使用友盟的网址(等微信审核通过后，将key替换)
    [UMSocialWechatHandler setWXAppId:@"wx523a41edbc15703a" appSecret:@"d4624c36b6795d1d99dcf0547af5443d" url:callBackURL];
    
    //打开新浪微博的SSO开关(sso机制就是先检测iphone里有没有官方的新浪微博客户端，如果有，则打开它帮助认证，没有就调用OAuth2.0机制进行授权)
    [UMSocialSinaHandler openSSOWithRedirectURL:callBackURL];
    
    //    //设置分享到QQ空间的应用Id，和分享url 链接
    [UMSocialQQHandler setQQWithAppId:@"1104968158" appKey:@"r0b8r5yQGhoIFlnv" url:callBackURL];
}

/**
 这里处理新浪微博SSO授权之后跳转回来，和微信分享完成之后跳转回来
 */
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return  [UMSocialSnsService handleOpenURL:url];
}

/**
 这里处理新浪微博SSO授权进入新浪微博客户端后进入后台，再返回原来应用
 */
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [UMSocialSnsService  applicationDidBecomeActive];
}


- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return  [UMSocialSnsService handleOpenURL:url];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}




@end
